package antidestiny.java2dex.utils;

/**
 * Created by Hero on 2017/1/2.
 */

public class StringCheck {
    public static String checkProjectName(String name){
        if (name==null||name.length()==0)return "工程名为空";
        if (contains(name,'.','/')) return "含有非法字符";
        return  null;
    }

    public static String checkPackage(String packageStr){
        if (packageStr==null||packageStr.length()==0)return "包名为空";
        char[] content=packageStr.toCharArray();
        for(Character c:content){
            if (c=='.'||(c>='A'&&c<='Z')||(c>='a'&&c<='z'))continue;
            return "包名含有非法字符：‘"+c+"’";
        }
        if (packageStr.startsWith("."))
            return "以'.'开头";
        if (packageStr.endsWith("."))
            return "以'.'结尾";
        return null;
    }

    public static String checkProjectFileName(String fileName){
        if (fileName==null)return  "文件名不能为空";
        if (contains(fileName,'/','\\','.')) return "文件名中检查到非法字符";
        return null;
    }

    /**
     * 如果含有任意字符，返回真
     */
    public static boolean contains(String str,char... chars){
        for(char c:chars){
            if (str.contains(String.valueOf(c)))return true;
        }
        return  false;
    }
}
